<?php
/**
 # com_jvframwork - JV Framework
 # @version		1.5.x
 # ------------------------------------------------------------------------
 # author    Open Source Code Solutions Co
 # copyright Copyright (C) 2011 joomlavi.com. All Rights Reserved.
 # @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL or later.
 # Websites: http://www.joomlavi.com
 # Technical Support:  http://www.joomlavi.com/my-tickets.html
-------------------------------------------------------------------------*/
defined('_JEXEC') or die('Restricted access');

define('CONTROLLER_PREFIX', 'JVFrameworkController');  
define('SAVE_MESSAGE', JText::_('ITEM SAVED'));
define('REMOVED', JText::_('ITEM REMOVED'));
define('CANCEL_MESSAGE', JText::_('CANCEL'));          
define('ERROR_MESSAGE', JText::_('ERROR'));

define('JVPATH_LIBRARIES',          JPATH_ADMINISTRATOR . DS .'components' . DS . 'com_jvframework' . DS);
define('JVPATH_BASETHEME',          JPATH_ROOT . DS .'components' . DS . 'com_jvframework' . DS.'basethemes'.DS);
define('JVPATH_BASELAYOUT',         JVPATH_BASETHEME.'layouts'.DS);
define('JVPATH_BASELAYOUT_MOBILE',  JVPATH_BASETHEME.'mobiles'.DS);
define('JVTEMPLATE',                'jv-framework');  
define('JVPATH_TEMPLATE',           JPATH_ROOT.DS.'templates'.DS);
define('JVPATH_ROOT',               JVPATH_TEMPLATE.JVTEMPLATE.DS);
define('JVPATH_THEME',              JVPATH_ROOT. 'themes'.DS);
JHTML::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_jvframework/helpers/html/');

if ( !function_exists('json_decode') ){    
    function json_decode($json, $assoc = false )
    {
        $comment = false;
        $out = '$x=';
     
        for ($i=0; $i<strlen($json); $i++)
        {
            if (!$comment)
            {
                if (($json[$i] == '{') || ($json[$i] == '['))       $out .= ' array(';
                else if (($json[$i] == '}') || ($json[$i] == ']'))   $out .= ')';
                else if ($json[$i] == ':')    $out .= '=>';
                else                         $out .= $json[$i];         
            }
            else $out .= $json[$i];
            if ($json[$i] == '"' && $json[($i-1)]!="\\")    $comment = !$comment;
        }
        eval($out . ';');

        if($assoc == false){
            $obj = new stdClass;
            if(count($x)){
                foreach($x as $key => $val){
                    $obj->$key = $val;
                }
            }
            
            return $obj;
            
        }else{
            return $x;    
        }
        
    }
}
if ( !function_exists('json_encode') ){
   function json_encode( $array ){

        if( !is_array( $array ) ){
            return false;
        }
    
        $associative = count( array_diff( array_keys($array), array_keys( array_keys( $array )) ));
        if( $associative ){
    
            $construct = array();
            foreach( $array as $key => $value ){
    
                // We first copy each key/value pair into a staging array,
                // formatting each key and value properly as we go.
    
                // Format the key:
                if( is_numeric($key) ){
                    $key = "key_$key";
                }
                $key = "'".addslashes($key)."'";
    
                // Format the value:
                if( is_array( $value )){
                    $value = json_encode( $value );
                } else if( !is_numeric( $value ) || is_string( $value ) ){
                    $value = "'".addslashes($value)."'";
                }
    
                // Add to staging array:
                $construct[] = "$key: $value";
            }
    
            // Then we collapse the staging array into the JSON form:
            $result = "{ " . implode( ", ", $construct ) . " }";
    
        } else { // If the array is a vector (not associative):
    
            $construct = array();
            foreach( $array as $value ){
    
                // Format the value:
                if( is_array( $value )){
                    $value = json_encode( $value );
                } else if( !is_numeric( $value ) || is_string( $value ) ){
                    $value = "'".addslashes($value)."'";
                }
    
                // Add to staging array:
                $construct[] = $value;
            }
    
            // Then we collapse the staging array into the JSON form:
            $result = "[ " . implode( ", ", $construct ) . " ]";
        }
    
        return $result;
    }
}